package mao.exaimnation.meituan;

import java.util.*;

/**
 * @author Totoro
 * @date 2020/8/29
 * @explain:
 */
public class Main {
    public static  ArrayList<Integer>[] adjs;
    public static  int a = -1;
    public static boolean find = false;
    public static int b = 0;
    public static int maxB = 0;
    public static int target ;
    public static Set<Integer> set;
    public static  boolean[] marked_1;


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            int index_1 = scanner.nextInt();
            int index_2 = scanner.nextInt();
            target = index_2;
            set = new HashSet<>();
            adjs = new ArrayList[n];
            for (int i = 0; i < adjs.length; i++) {
                adjs[i] = new ArrayList<>();
            }
            for (int i = 0; i < n; i++) {
                int start = scanner.nextInt();
                int end = scanner.nextInt();
                adjs[start].add(end);
                adjs[end].add(start);
            }
            boolean[] marked = new boolean[n];
            bfs(index_1,marked);
            bfs(index_2,marked_1);
            System.out.println(a+maxB);

        }

    }

    public static void bfs (int start,boolean[] marked){
        if (find) return ;

        marked[start] = true;
        a++;


        if (start == target){
            find = true;
           marked_1 = Arrays.copyOf(marked,marked.length);
            return;
        }

        List<Integer> adj = adjs[start];
        for (Integer integer : adj) {
            if (!marked[integer]) {
                bfs(start,marked);
            }
        }

        a--;
        marked[start] = false;
    }

    public  void bfs_1 (int start,boolean[] marked){
        //if (find) return ;

        marked[start] = true;
        b++;
        maxB = Math.max(b,maxB);

        List<Integer> adj = adjs[start];
        for (Integer integer : adj) {
            if (!marked[integer]) {
                bfs_1(start,marked);
            }
        }

        b--;
        marked[start] = false;
    }
}
